﻿''' <summary>
''' Provides the basic container for game backgrounds.  Custom backgrounds can be derived from this class, however
''' the provided StaticBackground and ScrollingBackground classes can suffice in many cases.
''' </summary>
''' <remarks></remarks>
Public MustInherit Class GameBackground
    Public Event Load As EventHandler(Of GameEngineEventArgs)
    Public Event Draw As EventHandler(Of DrawEventArgs)
    Public Event Update As EventHandler(Of GameEngineEventArgs)

    Protected _UniqueID As Guid
    Public ReadOnly Property UniqueID As Guid
        Get
            Return _UniqueID
        End Get
    End Property

    Protected _Enabled As Boolean = True
    Public Property Enabled() As Boolean
        Get
            Return _Enabled
        End Get
        Set(ByVal value As Boolean)
            _Enabled = value
        End Set
    End Property

    Protected _EnableRaisingEvents As Boolean
    Public Property EnableRaisingEvents() As Boolean
        Get
            Return _EnableRaisingEvents
        End Get
        Set(ByVal value As Boolean)
            _EnableRaisingEvents = value
        End Set
    End Property

    Protected _BackgroundImage As String = String.Empty
    Public Property BackgroundImage() As String
        Get
            Return _BackgroundImage
        End Get
        Set(ByVal value As String)
            If value Is Nothing Then value = String.Empty
            _BackgroundImage = value
        End Set
    End Property

    Protected _IsLoaded As Boolean
    Public ReadOnly Property IsLoaded As Boolean
        Get
            Return _IsLoaded
        End Get
    End Property

    Protected _Name As String = String.Empty
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

    Protected _Visible As Boolean = True
    Public Property Visible() As Boolean
        Get
            Return _Visible
        End Get
        Set(ByVal value As Boolean)
            _Visible = value
        End Set
    End Property

    Protected _ZOrder As Integer
    Public Property ZOrder() As Integer
        Get
            Return _ZOrder
        End Get
        Set(ByVal value As Integer)
            _ZOrder = value
        End Set
    End Property

    Public Sub New()
        _UniqueID = Guid.NewGuid
        _Name = "New GameObject"
        _Enabled = True
    End Sub

    Protected Friend Overridable Sub OnLoad(ByVal e As GameEngineEventArgs)
        If _IsLoaded Then Exit Sub
        If _EnableRaisingEvents Then RaiseEvent Load(Me, e)
        _IsLoaded = True
    End Sub

    Protected Friend Overridable Sub OnDraw(ByVal e As DrawEventArgs)
        If _EnableRaisingEvents Then RaiseEvent Draw(Me, e)
    End Sub

    Protected Friend Overridable Sub OnUpdate(ByVal e As GameEngineEventArgs)
        If _EnableRaisingEvents Then RaiseEvent Update(Me, e)
    End Sub
End Class
